import json

s = '{"name":"张三"}'
s2 = '[{"name":"张三","info":[{"address":"北京路","phone":"2345345"}]},{"name":"李四","info":[{"address":"南京路","phone":"53624242"}]}]'
# 将字符串转为对象
obj = json.loads(s)
print(type(obj))
print(obj)
list_a = json.loads(s2)
print(type(list_a))
print(list_a[0]['info'][0]['phone'])
# 将数据保存到文件
json.dump(list_a, open('user.json', 'w', encoding='utf-8'), ensure_ascii=False)
# 读取json文件数据到内存
ls = json.load(open('user.json', encoding='utf-8'))
print(ls)
